package com.zty.xiaomiadmin.server.Controller;

import com.zty.xiaomiadmin.server.Entity.Result;
import com.zty.xiaomiadmin.server.Service.User.UserServiceImp;
import com.zty.xiaomiadmin.server.Vo.User.UserData;
import com.zty.xiaomiadmin.server.Vo.User.UserResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@CrossOrigin
@RestController
@RequestMapping("User")
public class UserController {

    @Autowired
    private UserServiceImp userServiceImp;

    @RequestMapping("/getUsers")
    public UserResult getUsers() throws IOException {
        UserResult userResult = userServiceImp.getUsers();
        return userResult;
    }

    @PostMapping("/editUser")
    public Result editUser(@RequestBody UserData userData) throws IOException {
        userServiceImp.editUser(userData);
        return new Result(200,"修改成功",null);
    }

    @PostMapping("/delUser")
    public Result delUser(String name) throws IOException {
        userServiceImp.delUser(name);
        return new Result(200,"删除成功",null);
    }
}
